package JavaEE.ManyThread2;
import java.util.*;
public class Demo1 {
    // throw用于处理main线程的中断异常:(不加则无法对main使用Thread.sleep()等某些方法)
    // 各种线程的get方法
    public static void main(String[] args) throws InterruptedException{
        Thread thread = new Thread(() -> {
            for(int i = 0;i < 5;i++){
                try {
                    // 无法通过thread.调用方法,是因为此时thread未完全初始化
                    // Thread.currentThread()为Thread中内置静态变量
                    // 调用时使用哪个线程,取决于当前位于哪个线程当中
                    System.out.println(Thread.currentThread().getName() + ":我还活着 " + i);
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName() + ":我即将死去");
        });
        System.out.println(thread.getName() + "ID: " + thread.getId());
        System.out.println(thread.getName() + "名称: " + thread.getName());
        System.out.println(thread.getName() + "状态: " + thread.getState());
        System.out.println(thread.getName() + "优先级: " + thread.getPriority());
        System.out.println(thread.getName() + "后台线程: " + thread.isDaemon());
        System.out.println(thread.getName() + "活着: " + thread.isAlive());
        System.out.println(thread.getName() + "被中断: " + thread.isInterrupted());
        thread.start();
        while(thread.isAlive()){}
        System.out.println(thread.getName() + "状态: " + thread.getState());
    }
}
